<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateChargeOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('charge_orders', function (Blueprint $table) {
            $table->increments('id');
            $table->string('order_sn')->comment('充值订单编号');
            $table->float('money')->comment('充值金额');
            $table->unsignedInteger('user_id')->comment('用户id');
            $table->string('status')->comment('订单状态 wait_pay 待支付；paid 已支付；');
            $table->string('pay_mode')->comment('支付方式 wxpay 微信支付；alipay 支付宝支付；');
            $table->string('out_trade_sn')->nullable()->comment('第三方支付单号');
            $table->string('source')->nullable()->comment('支付来源 wap:手机网站 web：网站 ios: ios客户端， android：安卓客户端');
            $table->timestamp('paid_at')->nullable()->comment('支付时间');
            $table->timestamps();

            $table->index('user_id');
            $table->unique('order_sn');
            $table->foreign('user_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('charge_orders');
    }
}
